import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controller/home_controller.dart';

class HomeView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      init: HomeController(),
      builder: (controller) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: PreferredSize(
            preferredSize:
                controller.body[controller.currentBottomIndex].preferredSize,
            child: AppBar(
              backgroundColor: controller
                  .body[controller.currentBottomIndex].backgroundColor,
            ),
          ),
          body: SafeArea(
            child: controller.body[controller.currentBottomIndex].widget,
          ),
          bottomNavigationBar: BottomNavigationBar(
            backgroundColor: Colors.white,
            showSelectedLabels: false,
            // 不显示选中的标签文字
            showUnselectedLabels: false,
            // 不显示未选中的标签文字
            currentIndex: controller.currentBottomIndex,
            onTap: (index) => controller.changeCurrentBottomIndex(index),
            selectedItemColor: Colors.red,
            unselectedItemColor: Colors.grey,
            type: BottomNavigationBarType.fixed,
            items: [
              BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: '',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.play_circle),
                label: '',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.favorite),
                label: '',
              ),
            ],
          ),
        );
      },
    );
  }
}
